package com.stock.stockana.ui.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.andexert.library.RippleView;
import com.stock.stockana.R;
import com.stock.stockana.StockCenter;
import com.stock.stockana.requests.GetVersionCode;
import com.stock.stockana.ui.activities.VersionNoticeActivity;

/**
 * Created by ljgsonx on 2016/3/4.
 */
public class VersionNoticeFragment extends Fragment {

    private static final String TAG = "VersionNoticeFragment->";

    TextView versionNowTv;
    RippleView mVersionRv;
    RippleView mNoticeRv;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.version_notice_layout, container, false);
        versionNowTv = (TextView) view.findViewById(R.id.versionNowTv);
        versionNowTv.setText("v" + ((VersionNoticeActivity) getActivity()).getVersionName());
        mVersionRv = (RippleView) view.findViewById(R.id.checkVersionRv);
        mNoticeRv = (RippleView) view.findViewById(R.id.noticeRv);
        mVersionRv.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                GetVersionCode getVersionCode = GetVersionCode.build();
                StockCenter.doReq(getVersionCode);
                ((VersionNoticeActivity) getActivity()).showProgress("正在检查,请稍后...");
            }
        });
        mNoticeRv.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                getFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.in_from_right, R.anim.out_from_left,
                                R.anim.in_from_left, R.anim.out_from_right)
                        .replace(com.stock.publiclib.R.id.id_baseFrame, new NoticeWvFragment())
                        .addToBackStack(null).commit();
            }
        });
        return view;
    }
}
